﻿using UnityEngine;
using System.Collections;

namespace Battle
{
    public class BattleResultPanel : MonoBehaviour
    {
        public enum ResultPanelType
        {
            Unknown,
            Win,
            Lose
        }
        public GameObject winObj;
        public GameObject loseObj;
        public GameObject unknownObj;

        public const string winAudioName = "Win";
        public const string lostAudioName = "Lost";

        AudioSource audioSource = null;

        public void ShowResult(ResultPanelType t)
        {
            if (t == ResultPanelType.Win)
            {
                winObj.SetActive(true);
                loseObj.SetActive(false);
                unknownObj.SetActive(false);
                if (audioSource == null)
                {
                    audioSource = AudioManager.Instance.PlayUIAudioWithReturn(winAudioName);
                }

                if (StaticData.curBattleData.battleType == BattleType.PVE)
                {
                    winObj.GetComponent<BoxCollider>().enabled = false;
                }
                else
                {
                    winObj.GetComponent<BoxCollider>().enabled = true;
                }
            }
            else if (t == ResultPanelType.Lose)
            {
                winObj.SetActive(false);
                loseObj.SetActive(true);
                unknownObj.SetActive(false);
                if (audioSource == null)
                {
                    audioSource = AudioManager.Instance.PlayUIAudioWithReturn(lostAudioName);
                }
            }
            else if (t == ResultPanelType.Unknown)
            {
                winObj.SetActive(false);
                loseObj.SetActive(false);
                unknownObj.SetActive(true);
            }
        }

        public void Hide()
        {
            winObj.SetActive(false);
            loseObj.SetActive(false);
            unknownObj.SetActive(false);
            if (audioSource != null)
            {
                audioSource.Stop();
                GameObject.Destroy(audioSource.gameObject);
            }
        }

        public void OnResultPanelClick()
        {
            BattleNetOver.OnShowBattleBalance();
            BattleManager.isBattleUI = false;
            //UIAutoSize.Instance.ShowMaskUI(true);
            if (audioSource != null)
            {
                audioSource.Stop();
                GameObject.Destroy(audioSource.gameObject);
            }
        }
 
    }
}